package com.jmxcfc.blfsc.jiwei.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jmxcfc.blfsc.common.common.request.BaseRequest;
import com.jmxcfc.blfsc.common.common.response.BaseResponse;
import com.jmxcfc.blfsc.common.sms.SmsRequest;
import com.jmxcfc.blfsc.common.sms.extend.SmsExtend;
import com.jmxcfc.blfsc.jiwei.service.ISmsRequestService;
import com.jmxcfc.fs.common.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 极微短信信息表 前端控制器
 * </p>
 *
 * @author pbs
 * @since 2023-10-24 11:7:45
 */
@RestController
@RequestMapping("/sms")
@Slf4j
public class JiWeiMessageInfoController {

    private ISmsRequestService smsRequestService;

    @Autowired
    public void setSmsRequestService(ISmsRequestService smsRequestService) {
        this.smsRequestService = smsRequestService;
    }

    /**
     * 发送短信请求入口
     * 1、serialSeq=集微的transactionId事务ID 字段
     * 2、扩展字段:acctNo账号、acctPassword密码
     * @param request
     * @return
     */
    @PostMapping("/request")
    public Result<BaseResponse<JSONObject>> request(@RequestBody BaseRequest<SmsRequest<SmsExtend>> request) {
        log.info("集微发送短信请求,请求参数:{}", JSON.toJSONString(request));
        BaseResponse<JSONObject> response = smsRequestService.sendRequest(request);
        log.info("集微发送短信请求,响应结果:{}", JSON.toJSONString(response));
        return Result.success(response);
    }

}
